package de.baumann.browser.activitys.hash

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.support.v7.widget.LinearLayoutManager
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import de.baumann.browser.OdinGlideModule
import de.baumann.browser.R
import de.baumann.browser.adapter.HashRankingAdapter
import de.baumann.browser.api.net.vo.LoginInfo
import de.baumann.browser.base.BaseOdinActivity
import de.baumann.browser.iview.IHashRankingView
import de.baumann.browser.present.LeaderboardPresenter
import de.baumann.browser.utils.StringUtil
import kotlinx.android.synthetic.main.activity_leaderboard.*
import kotlinx.android.synthetic.main.include_tool_bar.*
import java.math.BigDecimal

/**
 *@author:
 *@date:2019/7/3 10:44
 *@discription: 排行榜
 */
@Deprecated("5.0.0版本删除")
class LeaderboardActivity : BaseOdinActivity<IHashRankingView, LeaderboardPresenter>(), IHashRankingView {

    private lateinit var hashRankingAdapter: HashRankingAdapter

    companion object {
        fun startLeaderBoardActivity(context: Context) {
            context.startActivity(Intent(context, LeaderboardActivity::class.java))
        }
    }

    override fun getLayout(): Int {
        return R.layout.activity_leaderboard
    }

    override fun initView() {
        initToolbar(commToolBar,commTitle)
        rlTopBkg.post {
            val layoutParams = rlTopBkg.layoutParams as LinearLayout.LayoutParams
            layoutParams.height = (rlTopBkg.width * 1.114).toInt()
        }
        rvHashRanking.layoutManager = LinearLayoutManager(mContext)
        hashRankingAdapter = HashRankingAdapter(R.layout.recycler_item_hash_ranking)
        rvHashRanking.adapter = hashRankingAdapter
    }

    override fun createPresenter(): LeaderboardPresenter {
        return LeaderboardPresenter()
    }

    override fun createView(): IHashRankingView {
        return this
    }

    override fun initData() {
        presenter.getHashRanking()
    }

    override fun getTitleText(): String {
        return getString(R.string.computing_ranking)
    }

    @SuppressLint("SetTextI18n")
    override fun setChampion(hashRanking: LoginInfo?) {
        val ivLeaderHead = llChampion.findViewById<ImageView>(R.id.ivLeaderHead)
        OdinGlideModule.loadWithCropAndCircle(mContext, hashRanking?.headUrl, ivLeaderHead, R.drawable.icon_head)
        llChampion.findViewById<TextView>(R.id.tvLeaderPhone).text = StringUtil.mobileHide(hashRanking?.phone)
        val bigDecimal = BigDecimal(hashRanking?.contribute)
        tvChampionHash.text = bigDecimal.setScale(4, BigDecimal.ROUND_HALF_UP).toString()
    }

    @SuppressLint("SetTextI18n")
    override fun setSecondPlace(hashRanking: LoginInfo?) {
        val ivLeaderHead = llSecondPlace.findViewById<ImageView>(R.id.ivLeaderHead)
        OdinGlideModule.loadWithCropAndCircle(mContext, hashRanking?.headUrl, ivLeaderHead, R.drawable.icon_head)
        llSecondPlace.findViewById<TextView>(R.id.tvLeaderPhone).text = StringUtil.mobileHide(hashRanking?.phone)
        val bigDecimal = BigDecimal(hashRanking?.contribute)
        tvSecondPlaceHash.text = bigDecimal.setScale(4, BigDecimal.ROUND_HALF_UP).toString()
    }

    @SuppressLint("SetTextI18n")
    override fun setThirdPlace(hashRanking: LoginInfo?) {
        val ivLeaderHead = llThirdPlace.findViewById<ImageView>(R.id.ivLeaderHead)
        OdinGlideModule.loadWithCropAndCircle(mContext, hashRanking?.headUrl, ivLeaderHead, R.drawable.icon_head)
        llThirdPlace.findViewById<TextView>(R.id.tvLeaderPhone).text = StringUtil.mobileHide(hashRanking?.phone)
        val bigDecimal = BigDecimal(hashRanking?.contribute)
        tvThirdPlaceHash.text = bigDecimal.setScale(4, BigDecimal.ROUND_HALF_UP).toString()
    }

    override fun setRankingList(hashRankings: MutableList<LoginInfo>?) {
        hashRankingAdapter.setNewData(hashRankings)
    }

}
